/*
 * @Author: 郭招娣 10615594+guo-zhaodi@user.noreply.gitee.com
 * @Date: 2022-09-12 11:02:17
 * @LastEditors: 郭招娣 10615594+guo-zhaodi@user.noreply.gitee.com
 * @LastEditTime: 2022-09-16 08:47:24
 * @FilePath: \郭招娣\app\src\utils\request.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import axios from 'axios';

axios.defaults.baseURL='/api';
axios.defaults.timeout=6000;

// 添加请求拦截器
axios.interceptors.request.use(requestSuccess, requestError);

// 添加响应拦截器
axios.interceptors.response.use(responseSuccess, responseError);

function responseSuccess(config){
    const token = localStorage.getItem('token');

    if (token) {
        config.headers.Authorization = token;
    }
    return config;
}

function responseError(error){
    return Promise.reject(error);
}
function requestSuccess(config){
    return config;
}
function requestError(error){
    return Promise.reject(error);
}

export const getUrl = async (url, params) => await axios.get(url, { params })

export const postUrl = async (url, params)=> await axios.post(url, params)

export const putUrl = async (url, params) => await axios.put(url, params)

export const deleteUrl = async (url, params) => await axios.delete(url, { params })